<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title></title>
</head>
<body>
<!--弹窗：编辑-->
<div th:fragment="memberlevelinfoAddOrUpdate" class="modal inmodal fade" id="memberlevelinfoAddOrUpdate_Modal"
     tabindex="-1" role="dialog" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span
                        class="sr-only">Close</span></button>
                <h4 class="modal-title">编辑会员等级信息</h4>
                <small class="font-bold"></small>
            </div>
            <div class="modal-body">
                <form role="form" id="memberlevelinfoAddOrUpdate_form">
                                                                        <input id="memberlevelinfoAddOrUpdate_id" name="id"
                                   type="hidden">
                                                                                                <div class="form-group"><label>版本</label> <input
                                    id="memberlevelinfoAddOrUpdate_version" name="version"
                                    type="text" placeholder="版本" class="form-control"></div>
                                                                                                <div class="form-group"><label>排序</label> <input
                                    id="memberlevelinfoAddOrUpdate_sort" name="sort"
                                    type="text" placeholder="排序" class="form-control"></div>
                                                                                                <div class="form-group"><label>创建人</label> <input
                                    id="memberlevelinfoAddOrUpdate_createUser" name="createUser"
                                    type="text" placeholder="创建人" class="form-control"></div>
                                                                                                <div class="form-group"><label>创建时间</label> <input
                                    id="memberlevelinfoAddOrUpdate_createTime" name="createTime"
                                    type="text" placeholder="创建时间" class="form-control"></div>
                                                                                                <div class="form-group"><label>更新人</label> <input
                                    id="memberlevelinfoAddOrUpdate_updateUser" name="updateUser"
                                    type="text" placeholder="更新人" class="form-control"></div>
                                                                                                <div class="form-group"><label>更新时间</label> <input
                                    id="memberlevelinfoAddOrUpdate_updateTime" name="updateTime"
                                    type="text" placeholder="更新时间" class="form-control"></div>
                                                                                                <div class="form-group"><label>备注</label> <input
                                    id="memberlevelinfoAddOrUpdate_remark" name="remark"
                                    type="text" placeholder="备注" class="form-control"></div>
                                                                                                <div class="form-group"><label>删除标识</label> <input
                                    id="memberlevelinfoAddOrUpdate_deleted" name="deleted"
                                    type="text" placeholder="删除标识" class="form-control"></div>
                                                                                                <div class="form-group"><label>等级编号</label> <input
                                    id="memberlevelinfoAddOrUpdate_levelCode" name="levelCode"
                                    type="text" placeholder="等级编号" class="form-control"></div>
                                                                                                <div class="form-group"><label>等级名称</label> <input
                                    id="memberlevelinfoAddOrUpdate_levelName" name="levelName"
                                    type="text" placeholder="等级名称" class="form-control"></div>
                                                                                                <div class="form-group"><label>等级图标</label> <input
                                    id="memberlevelinfoAddOrUpdate_levelIco" name="levelIco"
                                    type="text" placeholder="等级图标" class="form-control"></div>
                                                                                                <div class="form-group"><label>租户ID
            租户设置的会员等级</label> <input
                                    id="memberlevelinfoAddOrUpdate_tenantId" name="tenantId"
                                    type="text" placeholder="租户ID
            租户设置的会员等级" class="form-control"></div>
                                                            </form>
            </div>

            <div class="modal-footer">
                <button type="button" class="btn btn-white" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="memberlevelinfoAddOrUpdateObj.submitHandler()">
                    保存
                </button>
            </div>
        </div>
    </div>

    <script type="text/javascript" >
        $(function () {
                memberlevelinfoAddOrUpdateObj.myForm.validate({
                rules: memberlevelinfoAddOrUpdateObj.dataRule,
                submitHandler: function (form) {
                        memberlevelinfoAddOrUpdateObj.dataFormSubmit(form);
                }
            });
        })
        var memberlevelinfoAddOrUpdateObj = new Object({
            myForm: $('#memberlevelinfoAddOrUpdate_form'),
            myModal: $('#memberlevelinfoAddOrUpdate_Modal'),
            dataRule: {
                                                                            version: {required: true }
                    ,                                                                sort: {required: true }
                    ,                                                                createUser: {required: true }
                    ,                                                                createTime: {required: true }
                    ,                                                                updateUser: {required: true }
                    ,                                                                updateTime: {required: true }
                    ,                                                                remark: {required: true }
                    ,                                                                deleted: {required: true }
                    ,                                                                levelCode: {required: true }
                    ,                                                                levelName: {required: true }
                    ,                                                                levelIco: {required: true }
                    ,                                                                tenantId: {required: true }
                                                        },
        init: function (memberlevelinfoId) {
            if(memberlevelinfoId){
                $.myGet({
                    url: `/member/memberlevelinfo/info/${memberlevelinfoId}`,
                    success: function (data) {
                        if (data && data.code === 0) {
                            memberlevelinfoAddOrUpdateObj.fillForm(data.memberlevelinfo);
                        } else {
                            toastr.error(data.msg, '操作失败')
                        }
                    }
                })
            } else {
                memberlevelinfoAddOrUpdateObj.fillForm();
            }
            this.myModal.modal('show')
        }
        ,
        fillForm: function (data = {}) {
            let _self = this;
            _self.myForm[0].reset();
            _self.myForm.find(`[type='hidden']`).val("")
            for (let i in data) {
                if(_self.myForm.find(`[name=${i}]`).length > 0){
                    _self.myForm.find(`[name=${i}]`).val(data[i])
                }
            }
        }
        ,
        submitHandler: function () {
            this.myForm.submit();
        }
        ,
        dataFormSubmit: function (form) {
            let _self = this;
            let formVals = $(form).serializeArray();
            let data = {}
            for (let i = 0; i < formVals.length; i++) {
                data[formVals[i].name] = formVals[i].value;
            }
            $.myPost({
                url: `/member/memberlevelinfo/${'data.id' ? 'update' : 'save'}`,
                dataType: 'json',
                data: data,
                success: function (data) {
                    if (data && data.code === 0) {
                        toastr.success(data.msg, '操作提示')
                        _self.myModal.modal('hide')
                        memberlevelinfoListObj.refreshDataList();
                        memberlevelinfoAddOrUpdateObj.fillForm();
                    } else {
                        toastr.error(data.msg, '操作失败')
                    }
                }
            })
        }
        })
    </script>
</div>
</body>
</html>